package com.ustc.hewei.nettyrpc2_0.common.serializer.impl.fastJson;

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONReader;
import com.ustc.hewei.nettyrpc2_0.common.enumeration.SerializerType;
import com.ustc.hewei.nettyrpc2_0.common.serializer.CommonSerializer;

/**
* @description: fastJson序列化
* @author hewei
* @date 2022/9/5 19:50
* @version 1.0
*/

public class FastJsonSerializer implements CommonSerializer {
    @Override
    public byte[] serializer(Object obj) {
        return JSON.toJSONBytes(obj);
    }

    @Override
    public <T> Object deSerializer(byte[] data, Class<T> clazz) {
        return JSON.parseObject(data, clazz, JSONReader.Feature.SupportClassForName);
    }

    @Override
    public int getCode() {
        return SerializerType.FAST_JSON.getCode();
    }
}
